define(["jquery", "juicer","core/util","core/personCfg"], function($, j,util,cfg) {

	var _tplDom = j(document.getElementById("tpl-person").innerHTML);

	var View = {

		createView: function() {
			var $div = $("<div/>").appendTo($("body"));
			$div.window({
				width: 720,
				height: 480,
				title: "个人中心",
				minimizable: false,
				collapsible: false,
				modal: true,
				cache:false,
				shadow:false,
				content: _tplDom.render(),
				openAnimation: "slide",
				onOpen: function() {
					setTimeout(function() {

						View.initView();

					}, 1000)

				},
				onClose: function() {
					$div.window("destroy", true);
				}
			});
		},

		initView: function($dom) {
			var d = $("#session-grid");
			var jobId=$("#jobId").val();
			d.datagrid({
				fitColumns: true,
				url: "/session/query/"+jobId,
				toolbar: "#ft",
				onLoadSuccess: function(data) {},
				queryParams: {
					name: "testName"
				},
				columns: [
					[{
						field: 'SESSION_ID',
						title: '会话ID',
						width: 100,
						hidden:true
					}, {
						field: 'KEY_ID',
						title: 'KEY',
						width: 100
					}, {
						field: 'JOBID',
						title: '处理人',
						width: 100
					}, {
						field: 'CHANNEL',
						title: '来源',
						width: 100
					}, {
						field: 'CREATE_TIME',
						title: '创建时间',
						width: 100,
						formatter:util.timeFormat
					}, {
						field: 'START_TIME',
						title: '开始时间',
						width: 100,
						formatter:util.timeFormat
					}, {
						field: 'END_TIME',
						title: '结束时间',
						width: 100,
						align: 'right',
						formatter:util.timeFormat
					}, {
						field: 'STATUS',
						title: '状态',
						width: 100,
						align: 'right',
						formatter:util.sessionStatus
					}]
				]

			})

			var pg=$("#person-config-grid");
			if(cfg.get("PCFG_DATA")){
				pg.propertygrid({
					fit:true,
				 	scrollbarSize: 0,
	                showGroup:true,
	                scrollbarSize:0,
	                data:cfg.get("PCFG_DATA"),
	                onAfterEdit:function(ri,rd,changes){
	                	cfg.change("PCFG_DATA",rd.name,rd.value);
	                }
				})	
			}else{
				pg.propertygrid({
					fit:true,
				 	scrollbarSize: 0,
	              	url:'/agent/config/'+jobId,
	                method:'get',
	                showGroup:true,
	                scrollbarSize:0,
	                onLoadSuccess:function(data){
	                	cfg.set("PCFG_DATA",JSON.stringify(data));
	                },
	                onAfterEdit:function(ri,rd,changes){
	                	cfg.change("PCFG_DATA",rd.name,rd.value);
	                }
				})
			}
			
		
		}

	}



	return {

		run: function() {
			View.createView();
		}

	}

})